﻿using QuickChat_Service.Repositories.Database;
using QuickChat_Service.Repositories.Repositories.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace QuickChat_Service.Repositories.Repositories.Implementations
{
    public class EFChatSessionRepository : EFRepository<ChatSession>, IChatSessionRepository
    {
        public EFChatSessionRepository(QuickChatApplicationEntities context) : base(context) { }

        #region Interface Implementation

        public void Add(int sessionStartersId)
        {
            ChatSession newSession = new ChatSession() { 
                StartTime = DateTime.UtcNow,
                Messages = new List<Message>(),
                Talkers = new List<Talker>()
            };

            newSession.Talkers.Add(DbContext.Set<Talker>().Find(sessionStartersId));

            base.Add(newSession);
        }

        public void AddUserToSession(int userId, int sessionId)
        {
            Talker newSessionTalker = DbContext.Set<Talker>().Find(userId);

            base.GetById(sessionId).Talkers.Add(newSessionTalker);
        }

        public override void Delete(int sessionId)
        {
            base.Delete(sessionId);
        }

        public override ChatSession GetById(int sessionId)
        {
            return base.GetById(sessionId);
        }

        #endregion
    }
}